import request from '@/utils/request';
import {
  KConfigAddItem,
  KConfigUpdateItem,
  TableListParams,
  KConfigDeleteItem,
  KConfigGetConfigPreviewParam, KGetTemplatePreviewParam
} from './data.d';

export async function queryItemConfig(params?: TableListParams) {
  return request('/api/v1/kconfig/items', { params });
}

export async function queryTemplateConfig() {
  return request('/api/v1/kconfig/template');
}
export async function queryTemplateByID(params: KGetTemplatePreviewParam) {
  return request('/api/v1/kconfig/template/history', {params})
}

export async function removeItemConfig(params: KConfigDeleteItem) {
  return request('/api/v1/kconfig/items', {
    method: 'POST',
    data: {
      ...params,
      method: 'delete'
    },
  });
}

export async function addItemConfig(params: KConfigAddItem) {
  return request('/api/v1/kconfig/items', {
    method: 'POST',
    data: {
      ...params,
      method: 'post'
    }
  })
}

export async function updateItemConfig(params: KConfigUpdateItem) {
  return request('api/v1/kconfig/items', {
    method: 'POST',
    data: {
      ...params,
      method: 'update',
    },
  });
}


export async function updateTemplateConfig(params: {content: string}) {
  return request('/api/v1/kconfig/template', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function getConfigPreview(params: KConfigGetConfigPreviewParam) {
  const response = await request('/api/v1/kconfig/getconfig', {params});
  return {status: response.status, content: response.data}
}

export async function queryInstances() {
  return request('/api/v1/kconfig/instances');
}

export async function queryTempldateList() {
  return request('/api/v1/kconfig/templates');
}

export async function queryLock() {
  return request('/api/v1/kconfig/lock/get', {
    method: 'POST',
  });
}
export async function deleteLock() {
  return request('/api/v1/kconfig/lock/delete', {
    method: 'POST',
  });
}
